const Mock = require('mockjs')

const List = []
const count = 24

const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'

for (let i = 0; i < count; i++) {
    List.push(Mock.mock({
        id: '@id',
        orderId: '@increment',//订单号
        clientName: '@cname',//终端客户名称
        storeName: '@cname',//店铺名称
        'totalMoney|1-100.1-10': 1,
        orderTime: '@date()'
    }))
}

module.exports = [
    {
        url: '/order/list',
        type: 'get',
        response: config => {
            const { orderId, storeName, currentPage = 1, pageSize = 10, sort } = config.query

            let mockList = List.filter(item => {
                if (orderId && item.orderId!=orderId) return false;
                if (storeName && item.storeName.indexOf(storeName) < 0) return false;
                return true;
            })

            const pageList = mockList.filter((item, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1))

            return {
                status:'ok',
                code: 0,
                message:'',
                serverTime:new Date().getTime(),
                data: {
                    total: mockList.length,
                    currentPage: parseInt(currentPage),
                    pageSize:pageSize,
                    pages: 0,
                    list: pageList
                }
            }
        }
    },{
        url: '/order/detail',
        type: 'get',
        response: config => {
            const { orderId } = config.query

            let selected = {};
            for (const item of List) {
                if(item.orderId == orderId){
                    selected = item;
                }
            }
            return {
                status:'ok',
                code: 0,
                message:'',
                data: selected
            }
        }
    }]

